package com.utils.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;

public class StringDate {
    public static void main(String[] args) {

        Date1();

    }

    public static void Date0(){
        //LocalDate date = LocalDate.parse("2018-09-16");

        String time = "2020-02-13 16:01:30";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = sdf.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println(date);
    }

    public static void Date1(){
        // 获取当前日期前一天的日期
        LocalDate localDate = LocalDate.now().minusDays(1);
        // 获取时间字符串如: 2021-03-01
        System.out.println(localDate.toString());
        // 获取当前年如 2021
        System.out.println(localDate.getYear());
        // 获取当前月如 3
        System.out.println(localDate.getMonthValue());
        // 获取当前天如 1
        System.out.println(localDate.getDayOfMonth());

    }
}
